import os
import requests

"""
2022年3月24日：使用requests包上传multipartFile文件
"""

def upload_multipart_file(file_path):
    url = "http://127.0.0.1:8080/consultant/poster_upload/batch"
    data = {

    }

    files = {
        "poster": open(file_path, "rb")
    }

    headers = {
        "userId": "1012"
    }

    response = requests.post(url, data=data, files=files, headers=headers)
    print(response.json())


if __name__ == '__main__':
    root_path = "C:\\Users\\slb0125\\Downloads\\2022年3月21日-规划师个人形象海报自测\\dev"

    count = 1
    for root, dirs, files in os.walk(root_path):
        sum = str(files.__len__())
        for file in files:
            print("共计" + sum + "个文件--" + "正在上传第" + str(count) + "个文件:" + file)
            count += 1

            upload_multipart_file(root_path + "\\" + file)

            print("第" + str(count) + "个文件上传完成:" + file)
            print("")
